//
//  JMCodeGroup.m
//  OpenSesame
//
//  Created by zhangjiaming on 16/1/19.
//  Copyright © 2016年 OpenSesame. All rights reserved.
//

#import "JMCodeGroup.h"
#import "JMCode.h"

@implementation JMCodeGroup
+ (NSArray *)codeGroupList {
    // 加载json数据
    NSString *path = [[NSBundle mainBundle] pathForResource:@"doorma.json" ofType:nil];
    NSData *data = [NSData dataWithContentsOfFile:path];
    NSArray *dicArray = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil];
    
    // 字典转模型
    NSMutableArray *temArr = [NSMutableArray array];
    for (NSDictionary *dict in dicArray) {
        JMCodeGroup *codeGroup = [self codeGroupWithDict:dict];
        [temArr addObject:codeGroup];
    }
    return temArr;
}

- (instancetype)initWithDict:(NSDictionary *)dict {
    if (self = [super init]) {
        [self setValuesForKeysWithDictionary:dict];
        NSMutableArray *temArr = [NSMutableArray array];
        for (NSDictionary *dict in self.brands) {
            JMCode *code = [JMCode codeWithDict:dict];
            [temArr addObject:code];
        }
        self.brands = temArr;
    }
    return self;
}

+ (instancetype)codeGroupWithDict:(NSDictionary *)dict {
    return [[self alloc] initWithDict:dict];
}
@end
